<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Models\Asset;
use App\Models\AssetAffiliation;
use App\Models\AssetBrand;
use App\Models\AssetCategory;
use App\Models\AssetKeeper;
use App\Models\AssetLocation;
use App\Models\AssetStatus;
use App\Models\AssetVendor;
use Faker\Generator as Faker;


$factory->define(Asset::class, function (Faker $faker) {
    $primaryAssetCategories = AssetCategory::whereNull('parent_id')->get();
    $primaryCategory = $faker->randomElement($primaryAssetCategories);
    $subCategory = $faker->randomElement($primaryCategory->children);
    return [
        'name' => $faker->name,
        'product_model_number' => $faker->creditCardNumber,
        'category_id' => $primaryCategory->id,
        'sub_category_id' => $subCategory->id,
        'brand_id' => function () {
            return factory(AssetBrand::class)->create()->id;
        },
        'sn' => $faker->creditCardNumber,
        'status_id' => function () use ($faker) {
            return AssetStatus::find($faker->numberBetween(1, 4))->id;
        },
        'affiliation_id' => function () {
            return factory(AssetAffiliation::class)->create()->id;
        },
        'keeper_id' => function () {
            return factory(AssetKeeper::class)->create()->id;
        },
        'description' => $faker->paragraph,
        'marking_price' => $faker->randomNumber(3),
        'bid_price' => $faker->randomNumber(2),
        'bid_date' => $faker->date(),
        'vendor_id' => function () {
            return factory(AssetVendor::class)->create()->id;
        },
        'location_id' => function () {
            return factory(AssetLocation::class)->create()->id;
        },
    ];
});

$factory->define(AssetCategory::class, function (Faker $faker) {
    return [
        "name" => $faker->unique()->name . $faker->randomDigitNotNull,
        "parent_id" => null
    ];
});


$factory->define(AssetAffiliation::class, function (Faker $faker) {
    return [
        "name" => $faker->unique()->name . $faker->randomDigitNotNull
    ];
});

$factory->define(AssetBrand::class, function (Faker $faker) {
    return [
        "name" => $faker->company . $faker->randomNumber(3)
    ];
});

$factory->define(AssetKeeper::class, function (Faker $faker) {
    return [
        "name" => $faker->unique()->name . $faker->randomDigitNotNull
    ];
});
$factory->define(AssetLocation::class, function (Faker $faker) {
    return [
        "name" => $faker->unique()->city . $faker->randomNumber(3),
        "address" => $faker->address
    ];
});

$factory->define(AssetStatus::class, function (Faker $faker) {
    return [
        "name" => $faker->name
    ];
});

$factory->define(AssetVendor::class, function (Faker $faker) {
    return [
        "name" => $faker->unique()->company . $faker->randomNumber,
        "description" => $faker->paragraph,
        "address" => $faker->address,
        "fax" => $faker->phoneNumber,
        "email" => $faker->email,
        "contact_person_name" => $faker->name,
        "phone" => $faker->name
    ];
});
